#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<pthread.h>

void *start(void *arg)
{
	pthread_setcancelstate(PTHREAD_CANCEL_ENABLE,NULL);
	pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED,NULL);
	//for(int i=0;;i++)
	{	
		printf("取消前\n");
		while(1)
		{
			sleep(1);
		}

		//printf("tid : %lu\n",pthread_self());
		//continue;
		//sleep(1);
	
	}
	return (void *)0;
}

int main()
{
	pthread_t tid;
	int ret;
	void *result;
	ret = pthread_create(&tid,NULL,start,NULL);
	if(ret)
	{
		printf("error!\n");
		exit(-1);
	}

	//pthread_join(tid,&result);
	sleep(1);
	pthread_cancel(tid);
	pthread_join(tid,&result);
	exit(0);

}

